#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_set>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<climits>
#define fi first
#define se second
#define SIZE(x) ((int)x.size())
#define out(x) cerr<<#x<<" = "<<(x)<<endl;
#define MP(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
#define VI vector<int>
#define VVI vector< vector<int> >
#define VD vector<double>
#define VVD vector<VD >
#define VC vector<char>
#define PI pair<int,int>
#define PL pair<ll,ll>
#define EPS 0.0000001


template<typename T> 
inline void read(T &x){
	x=0;T f=1;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

const ll maxn=10005;
struct no{
  ll a,b,tag,y,z;
  bool operator<(const no &x)const{
    if(y!=x.y)return y<x.y;
    return tag<x.tag;
  }
};
no ev[maxn<<1];
ll xx[maxn<<1];
ll dat[maxn<<1];
ll bl[maxn<<1];
ll mm[maxn<<1];
ll tg[maxn<<1];
ll evn,blo,xn;

void add(ll a,ll b,ll z){
  for(ll i=a;bl[i]==bl[a]&&i<=b;i++){
    dat[i]+=z;
  }
  mm[bl[a]]=0;
  for(ll i=(bl[a]-1)*blo+1;i<=bl[a]*blo;i++){
    mm[bl[a]]=max(mm[bl[a]],dat[i]);
  }
  mm[bl[a]]+=tg[bl[a]];
  if(bl[a]!=bl[b]){
    for(ll i=b;bl[i]==bl[b];i--){
      dat[i]+=z;
    }
    mm[bl[b]]=0;
    for(ll i=(bl[b]-1)*blo+1;i<=bl[b]*blo&&i<=xn;i++){
      mm[bl[b]]=max(mm[bl[b]],dat[i]);
    }
    mm[bl[b]]+=tg[bl[b]];
  }
  for(ll i=bl[a]+1;i<bl[b];i++){
    tg[i]+=z;
    mm[i]+=z;
  }
}
ll que(){
  ll res=0;
  for(int i=1;(i-1)*blo<xn;i++)res=max(res,mm[i]);
  return res;
}

int main(){
    #ifdef BUG
    freopen("a.in","r",stdin);
    #endif
    int t;
    read(t);
    while(t--){
      ll n,w,h;
      read(n);read(w);read(h);
      evn=0;
      ll x,y,z;
      xn=0;
      for(int i=0;i<n;i++){
	read(x);read(y);read(z);
	ev[++evn]={x,x+w,1,y,z};
	ev[++evn]={x,x+w,-1,y+h,z};
	xx[++xn]=x;
	xx[++xn]=x+w;
      }
      sort(ev+1,ev+evn+1);
      sort(xx+1,xx+xn+1);
      xn=unique(xx+1,xx+xn+1)-xx-1;
      blo=sqrt(xn);
      for(int i=1;i<=xn;i++)bl[i]=(i-1)/blo+1;
      memset(dat,0,sizeof dat);
      memset(tg,0,sizeof tg);
      memset(mm,0,sizeof mm);
      ll res=0;
      for(int i=1;i<=evn;i++){
	ll p=lower_bound(xx+1,xx+xn+1,ev[i].a)-xx;
	ll q=lower_bound(xx+1,xx+xn+1,ev[i].b)-xx;
	if(ev[i].tag==-1){
	  add(p,q-1,-ev[i].z);
	}else{
	  add(p,q-1,ev[i].z);
	  res=max(res,que());
	}
      }
      cout<<res<<endl;
    }
}